function qw(ooo){
  return document.querySelector(ooo)
}
qw()

async function fn(){
  //todo ===================省份=========================
   axios.defaults.baseURL = 'http://124.223.14.236:3001/api'
 const {data:res} = await axios.get('/city/province')
 console.log(res);
 const strhtml = res.data.map(function(item){
    return `
    <option value="${item.province}">${item.name}</option>
    `
 }).join('')
 qw('#province').innerHTML ='<option value="">请选择省份</option>' + strhtml
 qw('#province').value = '34'

 //todo ===================城市=========================
 const {data:res1} = await axios.get('/city/city',{
  params:{
    provinceCode:'34'
  }
 })
 console.log(res1);
 const gethtml = res1.data.map(function(item){
    return `
    <option value="${item.city}">${item.name}</option>
    `
 }).join('')
 qw('#city').innerHTML ='<option value="">请选择城市</option>' + gethtml
 qw('#city').value = '13'

  //todo ===================区县=========================
  const {data:res2} = await axios.get('/city/area',{
    params:{
      provinceCode:'34',
      cityCode:'13'
    }
   })
   console.log(res2);
   const posthtml = res2.data.map(function(item){
      return `
      <option value="${item.area}">${item.name}</option>
      `
   }).join('')
   qw('#county').innerHTML ='<option value="">请选择区县</option>' + posthtml
   qw('#county').value = '22'
}
fn()

//todo============省发生改变，找到对应的市=============
qw('#province').addEventListener('change',async function(){
  console.log(this.value);
  const {data:res1} = await axios.get('/city/city',{
    params:{
      provinceCode:this.value
    }
   })
   console.log(res1);
   const gethtml = res1.data.map(function(item){
      return `
      <option value="${item.city}">${item.name}</option>
      `
   }).join('')
   qw('#city').innerHTML ='<option value="">请选择城市</option>' + gethtml
   //todo===========重新渲染区县============
   qw('#county').innerHTML ='<option value="">请选择区县</option>'
})

//todo============市发生改变，找到对应的区县=============
qw('#city').addEventListener('change',async function(){
  console.log(this.value);
  const {data:res2} = await axios.get('/city/area',{
    params:{
      provinceCode:qw('#province').value,
      cityCode:this.value
    }
   })
   console.log(res2);
   const posthtml = res2.data.map(function(item){
      return `
      <option value="${item.area}">${item.name}</option>
      `
   }).join('')
   qw('#county').innerHTML ='<option value="">请选择区县</option>' + posthtml
})
